﻿using System;
using System.ComponentModel.Composition;
using System.Net;
using System.Runtime.InteropServices;
using System.Text;
using SNSpirit.InteropServices;

namespace SNSpirit.Service.Web
{
    [Export(typeof(ICookieService)), PartCreationPolicy(CreationPolicy.Shared)]
    public class CookieService : ICookieService
    {
        public Cookie GetCookie(string uri, string name, CookieFlag flag)
        {
            StringBuilder sBuilder = new StringBuilder();
            UInt32 size = 256;

            if (InteropServices.Utility.InternetGetCookieEx(uri, name, sBuilder, ref size, (int)flag, IntPtr.Zero))
            {
                // get cookie
                return null;
            }
            else
            {
                // get last error
                int error = Marshal.GetLastWin32Error();
                throw new InvalidOperationException(error.ToString());
            }
        }

        public void SetCookie(Cookie cookie)
        {
            throw new NotImplementedException();
        }
    }
}